#!/bin/zsh

clear

work_dir=$PWD
echo "正在编译整个框架库 ..."

if [ ! -f "lmake.sh" ]; then
	echo "当前目录与该脚本不在同一层"
	exit 1
fi

if [ ! -d "lib" ]; then
	echo "创建 lib 目录"
	mkdir $work_dir/lib
	if [ ! $? -eq 0 ]; then
		echo "创建 lib 目录失败"
		exit 1
	fi
else
	rm -rf $work_dir/lib/*
fi

if [ ! -d "lib_src" ]; then
	echo "未找到库源文件目录"
	exit 1
else
	echo "进入库源文件目录 lib_src/"
	cd $work_dir/lib_src
fi

if [ ! -d "build" ]; then
	echo "创建 build 目录"
	mkdir $work_dir/lib_src/build
	if [ ! $? -eq 0 ]; then
		echo "创建 build 目录失败"
		exit 1
	fi
else
	rm -rf build/*
fi

echo "进入build目录"
cd build
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=YES ..
make -j2
cd $work_dir

